package cesaredu.midchat;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import cesaredu.midchat.middleware.MidChatCommunication;
import cesaredu.midchat.middlewaremetrics.MiddlewareMetrics;
import cesaredu.midchat.phoneinformation.PhoneInformation;

public class MainActivity extends Activity {

	private PhoneInformation phoneInfo;
	private MidChatCommunication middleware;
	private MiddlewareMetrics middlewareMetrics;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_main);
		
		final Button btnStartMetrics = (Button)this.findViewById(R.id.btnStartMetrics);
		final Button btnMostrarMedia = (Button)this.findViewById(R.id.btnMostrarMedia);
		final TextView txtTempoMedio = (TextView)this.findViewById(R.id.txtTempoMedio);
		
		this.phoneInfo = new PhoneInformation(this);
		this.middleware = new MidChatCommunication(this, this.phoneInfo.getLocalPhoneNumber());
		this.middlewareMetrics = new MiddlewareMetrics(middleware);
		
		btnStartMetrics.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				MainActivity.this.middlewareMetrics.startMeasure();
			}
		});
		
		btnMostrarMedia.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				long media = MainActivity.this.middlewareMetrics.getMedia();
				txtTempoMedio.setText("Tempo medio" + media);
			}
		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}